package com.robot.mirai.controller.interview.listener;

import com.robot.mirai.config.listener.GlobalEventChannelListener;
import jakarta.annotation.Resource;
import kotlinx.coroutines.CompletableJob;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.event.Listener;
import net.mamoe.mirai.event.ListeningStatus;
import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.message.data.Message;
import net.mamoe.mirai.message.data.MessageChain;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SeekersEventListener {
    @Resource
    private Bot bot;
    @Autowired
    GlobalEventChannelListener channelListener;
    public void addSeekersUser(){
        CompletableJob completableJob = channelListener.getEventChannelListener();
        Listener<MessageEvent> messageEventListener = bot.getEventChannel().parentJob(completableJob).subscribe(MessageEvent.class, messageEvent -> {
            if (messageEvent.getMessage().contentToString().equals("添加求职者")) {
                MessageChain chain=new MessageChainBuilder().append("输入姓名：\n输入姓名：\n输入职位：\n").build();
                messageEvent.getSender().sendMessage(chain);
                return ListeningStatus.LISTENING;
            }
            return ListeningStatus.STOPPED;
        });

        //继续监听
        Listener<MessageEvent> listening = listening(messageEventListener,new MessageChainBuilder().append("123").build());
     }

    private Listener<MessageEvent> listening(Listener<MessageEvent> messageEventListener,Message replayMessage){
        return bot.getEventChannel().parentJob(messageEventListener).subscribe(MessageEvent.class, messageEvent -> {
            messageEvent.getSender().sendMessage(replayMessage);
            return ListeningStatus.STOPPED;
        });
    }
}
